<?php

include_once ("TaskHubDB.class.php");


class Device {
	/*
        public bool AddDevice (uint MyAccountID, string DeviceID, string URL) { return true; }
        public bool RemoveDevice(uint MyAccountID, string DeviceID) { return true; }
	*/

	//////////////////////////////////////////////////////////////////////////////////////////////////
	//  Public WS methods

	public function AddDevice ($data) {
		$params = get_object_vars($data);
		return Array (__FUNCTION__."Result" => $this->_AddDevice (
			$params["MyAccountID"], $params["DeviceID"], $params["URL"]
		));
	}

	public function RemoveDevice ($data) {
		$params = get_object_vars($data);
		return Array (__FUNCTION__."Result" => $this->_RemoveDevice (
			$params["MyAccountID"], $params["DeviceID"]
		));
	}

	public function GetDevices ($AccountID) {
		$result = mysql_query ("SELECT DeviceID,URL FROM Devices WHERE AccountID = '{$AccountID}'");
		if (! $result)
			return null;

		$return_array = Array ();
		while ($return_array[] = mysql_fetch_assoc ($result));
		return $return_array;
	}


	//////////////////////////////////////////////////////////////////////////////////////////////////
	//  Private raw methods

	private function _AddDevice ($MyAccountID, $DeviceID, $URL) {
		// Insert new Device //
		$result = mysql_query ("INSERT INTO Devices (AccountID,DeviceID,URL) VALUES ('{$MyAccountID}', '{$DeviceID}', '{$URL}')");
		if (! $result) {
			TaskHubDB::AddError (mysql_error ());
			return false;
		}

		return true;
	}

	private function _RemoveDevice ($MyAccountID, $DeviceID) {
		// Delete Contact //
		$result = mysql_query ("DELETE FROM Contacts WHERE AccountID = '{$MyAccountID}' AND ContactAccountID = '{$ContactAccountID}'");
		if (! $result) {
			TaskHubDB::AddError (mysql_error ());
			return false;
		}

		return true;
	}

}

?>